//
//  QLMNewZhenjiTabCell.m
//  Xiaomakuaixiu
//
//  Created by 龚碧容 on 2017/12/2.
//  Copyright © 2017年 hwd. All rights reserved.
//

#import "QLMNewZhenjiTabCell.h"
#import "QLMNewPjColCell.h"

@implementation QLMNewZhenjiTabCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    // Configure the view for the selected state
}

- (void)_creatmainUI{
    
    titleArr = [NSArray arrayWithObjects:@"土石方机械",@"路面机械",@"再制造机械",nil];
    imaNameArr = [NSArray arrayWithObjects:@"tushifang",@"lumian",@"zaizhizao",nil];
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.minimumInteritemSpacing = 0;// 垂直方向的间距
    layout.scrollDirection=UICollectionViewScrollDirectionHorizontal;
    layout.minimumLineSpacing = 0; // 水平方向的间距
    
    UICollectionView *_pjCollectionView=[[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, kScreen_width,120) collectionViewLayout:layout];
    _pjCollectionView.delegate=self;
    _pjCollectionView.dataSource=self;
    _pjCollectionView.showsHorizontalScrollIndicator=NO;
    _pjCollectionView.backgroundColor=[UIColor whiteColor];
    _pjCollectionView.alwaysBounceVertical = NO;
    _pjCollectionView.collectionViewLayout=layout;
    
    [_pjCollectionView registerClass:[QLMNewPjColCell class] forCellWithReuseIdentifier:@"QLMNewPjColCellId"];
    
    [self addSubview:_pjCollectionView];
}

+(instancetype)cellWithTableView:(UITableView *)tableView{
    static NSString *identifiew=@"QLMNewZhenjiTabCellId";
    QLMNewZhenjiTabCell *cell=[tableView dequeueReusableCellWithIdentifier:identifiew];
    if (cell==nil) {
        cell=[[QLMNewZhenjiTabCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifiew];
    }
    [cell _creatmainUI];
    return cell;
}

#pragma mark - UICollectionView datasource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return titleArr.count;
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return CGSizeMake((kScreen_width)/3, 120);
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *identifiew=@"QLMNewPjColCellId";
    QLMNewPjColCell *pjCollectionCell=[collectionView dequeueReusableCellWithReuseIdentifier:identifiew forIndexPath:indexPath];
    pjCollectionCell.nameLabel.font=[UIFont systemFontOfSize:16];
    pjCollectionCell.nameLabel.text=titleArr[indexPath.row];
    pjCollectionCell.zhenjiImageView.image=[UIImage imageNamed:imaNameArr[indexPath.row]];
    
    return pjCollectionCell;
}

//- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
//    return UIEdgeInsetsMake(0, 5, 5, 5);
//}

#pragma mark -- UICollectionViewDelegate
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    [_delegate didselectItem:5460+indexPath.row];
}

@end
